package com.atguigu04.block;

/**
 * ClassName: PersonTest
 * Description:
 *
 * @Author liu
 * @Create 2024/11/8 21:59
 * @Version 1.0
 */
public class BlockTest {
    public static void main(String[] args) {
        //静态
        System.out.println(Person.info);//用来打印 info的值
        System.out.println();
        System.out.println(Person.info);

        //非静态
        System.out.println();
        Person p1 = new Person();
        Person p2 = new Person();
        System.out.println(p1.age);
    }


}

class Person{
    String name;
    int age;

    //静态属性
    static String info = "我是人";

    public void eat(){
        System.out.println("eat");
    }

    public Person(){
    }

    //非静态代码块
    {
        System.out.println("非静态代码块");
    }
    {
        System.out.println("非静态代码块2");
        age = 1;
        System.out.println("info= "+info);
    }

    //静态代码块（仅会调用一次）
    static{
        System.out.println("静态代码块");
    }
    static {
        System.out.println("静态代码块2");
        System.out.println("info= "+info);
    }
}